package com.xiang.api.common.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import com.xiang.api.Util;
import com.xiang.api.entity.Message;

@RestControllerAdvice
public class GlobalExceptionHandler {

  // @ExceptionHandler(value = RuntimeException.class)
  // @ResponseStatus(HttpStatus.BAD_REQUEST)
  @ResponseStatus(HttpStatus.OK)
  @ExceptionHandler(value = Exception.class)
  public String handler(Exception e) {
    String s = Util.errString(e);

    // e.printStackTrace();
    System.out.println("全局错误: " + s);
    return Util.toJString(new Message(s, true));
  }
}
